package button;

import java.awt.event.*;
import java.awt.geom.Rectangle2D;
import java.awt.*;

import utility.Utility;

public abstract class MyButton {
	protected int x;
	protected int y;
	protected int width;
	protected int height;
	private Color normalButtonColor;
	private Color pressedButtonColor;
	private Color normalBorderColor;
	private Color pressedBorderColor;
	private Color msgColor;
	private String msg;
	protected boolean isPressed;
	protected boolean isActive;
	
	public MyButton(int x, int y, int width, int height){
		this.x = x;
		this.y = y;
		this.width = width;
		this.height = height;
		isPressed = false;
		msgColor = Color.BLACK;
		msg = "test";
		
		isActive = true;
		normalButtonColor = new Color(255, 255, 255);
		normalBorderColor = new Color(0, 0, 0);
		pressedButtonColor = new Color(192, 255, 62);
		pressedBorderColor = new Color(0, 0, 0);
	}
	
	public abstract void pressed(MouseEvent e);
	public abstract void released(MouseEvent e);
	
	public void draw(Graphics2D g){
		Color c = g.getColor();
		if(!isPressed){
			g.setColor(normalButtonColor);
			g.fillRect(x, y, width, height);
			g.setColor(normalBorderColor);
			g.drawRect(x, y, width, height);
		}else{
			g.setColor(pressedButtonColor);
			g.fillRect(x, y, width, height);
			g.setColor(pressedBorderColor);
			g.drawRect(x, y, width, height);
		}
		Point p = Utility.calculateStringLocationOneLine(this, g);
//System.out.println(p);
		g.setColor(msgColor);
		g.drawString(msg, (int)p.getX() , (int)p.getY());
		g.setColor(c);
	}
	public void setActiveFalse(){
		isActive = false;
	}
	public void setActiveTrue(){
		isActive = true;
	}
	
	
	
	
	
	public int getX(){
		return x;
	}
	public int getY(){
		return y;
	}
	public int getWidth(){
		return width;
	}
	public int getHeight(){
		return height;
	}
	public String getMsg(){
		return msg;
	}
	public void setX(int x) {
		this.x = x;	
	}
	public void setY(int y){
		this.y = y;
	}
}
